<template>
    <div>
        <h1>新增</h1>
        <hr>
        <label>
            <span>userName:</span>
            <input type="text" v-model="userName">
        </label>
        <br>
        <label>
            <span>userAge:</span>
            <input type="text" v-model="userAge">
        </label>
        <br>
        <label>
            <span>userAddress:</span>
            <input type="text" v-model="userAddress">
        </label>
        <br>
        <button @click="addData">确定</button>
    </div>
</template>

<script>
import axios from '@/service/httpService'

export default {
  data () {
    return {
      userName: '',
      userAge: '',
      userAddress: ''
    }
  },
  methods: {
    addData () {
      axios({
        method: 'post',
        url: '/addUser',
        data: {userName: this.userName, userAge: this.userAge, userAddress: this.userAddress}
      })
        .then(response => {
          console.log(response)
          this.$router.push({path: '/'})
        }).catch(error => {
          console.log(error)
        })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
tr {
    border: 1px solid #000;
}
</style>
